package com.quan.utils;

import java.text.FieldPosition;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.fasterxml.jackson.databind.util.StdDateFormat;

/**
 * 格式化日期
 * @author yhaoquan
 *
 */
public class CustomDateFormat extends StdDateFormat {

	private static final long serialVersionUID = -3201781773655300201L;

    public static final CustomDateFormat instance = new CustomDateFormat();

    @Override
    public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        StringBuffer formatBuf = sdf.format(date, toAppendTo, fieldPosition) ;
        
        String[] split = formatBuf.toString().split(" ") ;
        
        StringBuffer format = new StringBuffer() ;
        
        //如果时分秒为00:00:00则去除
        if(split[1].equals("00:00:00")) {
        	format.append(split[0]) ;
        } else {
        	format = formatBuf ;
        }
        return format;
    }

    @Override
    public CustomDateFormat clone() {
        return new CustomDateFormat();
    }


}
